<template>
  <div class="swiper">
    <swiper :options="swiperOption" v-if="showSwiper" ref="mySwiper">
      <swiper-slide v-for="item of swiperList" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" />
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    swiperList: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        autoplay: 1500,
        speed: 500,
        loop: true,
        observer: true,
        observeParents: true
      }
    }
  },
  computed: {
    showSwiper () {
      return this.swiperList.length
    }
  }
}
// 因为scoped的作用，该style标签只能在这个组件中起作用，并且.swiper-pagination-bullet-active是子组件swiper里定义的
// 该组件的style标签对该组件中的子组件不起作用，而此时>>>是指贯穿，使选择器不受scoped的作用，贯穿作用到子组件
// observer:true,修改swiper自己或子元素时，自动初始化swiper
// observeParents:true,修改swiper的父元素时，自动初始化swiper
</script>

<style lang="stylus" scoped>
  .swiper >>> .swiper-pagination-bullet-active
    background-color: #ffffff
  .swiper
    width: 100%
    height: 0
    padding-bottom: 31.25%
    overflow: hidden
    background-color: #eeeeee
  .swiper-img
    width: 100%
</style>
